<?php
/**
 * Created by PhpStorm.
 * User: wangsong
 * Time: 2018/5/30 17:18
 */

namespace App\Project\Image;

use Illuminate\Support\Str;

class Src
{
    protected $attribute;

    public function __construct($path)
    {
        if (0 !== strpos($path, '/storage/')) {
            $this->attribute = \Storage::url($path);
        } else {
            $this->attribute = $path;
        }
    }

    public function attribute()
    {
        return $this->attribute;
    }

    public function path()
    {
        return new Path(Str::replaceFirst('/storage', 'public', $this->attribute));
    }
}